package com.dayuanit.dy16.ebook.ebookweb.service.impl;

import com.dayuanit.dy16.ebook.ebookweb.service.IRedisService;
import com.dayuanit.dy16.ebook.ebookweb.vo.SettlementRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class RedisServiceImpl extends BaseService implements IRedisService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Resource(name = "redisTemplate")
    private ValueOperations<String, List<SettlementRequestVO>> settlementOps;

    @Override
    public void saveSettleInfo(long userId, List<SettlementRequestVO> settlements) {
        String key = "ebook:settlement:" + userId;
        settlementOps.set(key, settlements);
    }

    @Override
    public List<SettlementRequestVO> getSettleInfo(long userId) {
        String key = "ebook:settlement:" + userId;
        return settlementOps.get(key);
    }

    @Override
    public String getAreaValue(String code) {
        String key = "ebook:" + code;
        return (String) redisTemplate.opsForValue().get(key);
    }
}
